/**
 * 返回表单校验规则 rules
 */
export default function (item) {
  const res = {}
  if (item.required) {
    res[item.field] = [
      {
        required: true,
        message: '必须填写'
      }
    ]
    delete item.required
  }
  if (item.rules && !res[item.field]) {
    const rules = item.rules
    rules.forEach((rule) => {
      if (rule.required && !rule.message) {
        rule.message = '必须填写'
      }
      if (rule.pattern && !rule.message) {
        rule.message = '请设置正确的格式'
      }
    })
    res[item.field] = rules
    delete item.rules
  }
  return res
}
